<?php
set_time_limit(0);
require_once 'Zend/Loader.php';
require_once 'lib/amazon/amazon_api_class.php';
require_once 'class/Blogger.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>AMZ BLOG</title>
    </head>
    <body><center>
        <img src="http://1.bp.blogspot.com/-fW5IaZSh9h4/UpSOtl8JjwI/AAAAAAAAA-c/N0cvqeaqQTA/s200/Amazon-Logo.png"/>
       <?php
        if($_POST) {
            $asso       = trim($_POST['asso']);
            $public     = trim($_POST['public']);
            $private    = trim($_POST['private']);
            $keyword    = trim($_POST['keyword']);
            $bloggID    = trim($_POST['bid']);
            $email      = trim($_POST['email']);
            $pass       = trim($_POST['pass']);

            $obj_amazon = new AmazonProductAPI();
            $obj_amazon->setAssociateTag($asso);
            $obj_amazon->setPublicKey($public);
            $obj_amazon->setPrivateKey($private);

            try {




                if(strtoupper(substr($keyword, 0,4))== "ASIN") {
                    $ex_asin  =  explode(":", $keyword);
                    $asin     =  $ex_asin[1];
                    if($ex_asin[2])
                        $keyword  = $ex_asin[2];
                    $xml = $obj_amazon->getItemByAsin($asin);
                } else {
                    $xml = $obj_amazon->getRandomByKeyword($keyword);
                }

                /* Load XML Template Config */
                $config = @simplexml_load_file("template.xml");
                /* Post To Blogger */
                $obj_blogger = new Blogger();
                $param = array();
                $param['title']   = base64_decode($config->title);
                $param['content'] = base64_decode($config->content);
                $param['keyword'] = $keyword;
                $param['blog_id'] = $bloggID;
                $param['email']   = $email;
                $param['password']= $pass;

                if($obj_blogger->post($param,$xml)) {
                    echo '<div style="color:red;font-size:30px;border-top:2px dotted #ccc;border-bottom:2px dotted #ccc;background:#f2f2f2;padding:50px;text-decoration:blink;">
Post Delivered</div>';
                }
 


            }catch (Exception $e) {
                echo '<div style="color:red">***'.$e->getMessage().'***</div>';
            }
        }
        ?>
     




		<script>
setTimeout(function() {
document.forms[0].submit();
}, 30000000);
</script>
<div style="margin-top:5px">
        <a href ="template.php">Edit Template</a></div></center>
    </body>
</html>